function [video, nFrames, vidRows, vidCols] = loadVideo( videoType, videoDir, identifier )
%UNTITLED Summary of this function goes here
%   Returns a structure array of image frames. 
%   If type SeparateImages then identifier is the three letter file extension.  
%   If type is AVI, then identifier is the file name. 

    if strcmp(videoType, 'SeparateImages')
        
        %Determine number of frames, and the rows and cols in each frame
        list = dir(videoDir);
        nFiles = size(list,1);
        vidRows = 0;
        vidCols = 0;
        for i = 1:nFiles
           if list(i).isdir ~= 1
               t = strfind(list(i).name, identifier);
                if ~isempty(t)
                    imageFullPath = sprintf('%s%s',videoDir, list(i).name);
                    [image,~] = imread(imageFullPath,1);
                    [vidRows, vidCols] = size(image);
                    break;
                end
           end
        end
        

        %Load the video frames
       
        %mov(1:nFrames) = struct('cdata', zeros(vidHeight, vidWidth, 3, 'uint8'), ...
        % 'colormap', []);
        
        seqnum = 0;
        for i = 1:nFiles
           if list(i).isdir ~= 1
               t = strfind(list(i).name, identifier);
                if ~isempty(t)
                    seqnum = seqnum + 1; 
                    videoFullPath = sprintf('%s%s',videoDir, list(i).name);
                    [image,~] = imread(videoFullPath,1);

                     video(seqnum).gdata = image;
                    
                end
           end
        end
        nFrames = seqnum;
               
    % If it is an AVI file
    elseif strcmp(videoType, 'AVI')
        
        addpath(videoDir);
        fName = identifier;
        ledObj = VideoReader(fName);
        nFrames = ledObj.NumberOfFrames;
        vidRows = ledObj.Height;
        vidCols= ledObj.Width;
        get(ledObj);

        video(1:nFrames) = struct('cdata', zeros(vidRows, vidCols, 3, 'uint8'), ...
            'colormap', []);

        for k = 1 : nFrames

           video(k).cdata = read(ledObj, k);
           video(k).gdata = rgb2gray(video(k).cdata);

        end     
        
    end
end

